package com.ly.lypopupwindowdemo.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.ly.lypopupwindowdemo.R;
import com.ly.lypopupwindowdemo.pop.ScalePopup;
import com.ly.lypopupwindowdemo.pop.SlideFromBottomPopup;

import razerdp.basepopup.BasePopupWindow;

public class Main2Activity extends AppCompatActivity implements View.OnClickListener {


    Button scale_btn,from_bottom_btn,from_top_btn,auto_loca_btn;


    private View.OnClickListener listener = new View.OnClickListener(){

        @Override
        public void onClick(View v) {

            switch (v.getId()){
                case R.id.tx_1:
                    Toast.makeText(Main2Activity.this, "点击1", Toast.LENGTH_SHORT).show();
                    break;
                case R.id.tx_2:
                    Toast.makeText(Main2Activity.this, "点击2", Toast.LENGTH_SHORT).show();
                    break;
                case R.id.tx_3:
                    Toast.makeText(Main2Activity.this, "点击3", Toast.LENGTH_SHORT).show();
                    break;
                default:
                    break;
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        scale_btn = (Button) findViewById(R.id.scale_btn);
        from_bottom_btn = (Button) findViewById(R.id.from_bottom_btn);
        from_top_btn = (Button) findViewById(R.id.from_top_btn);
        auto_loca_btn = (Button) findViewById(R.id.auto_located_btn);



        scale_btn.setOnClickListener(this);
        from_bottom_btn.setOnClickListener(this);
        from_top_btn.setOnClickListener(this);
        auto_loca_btn.setOnClickListener(this);

        findViewById(R.id.popup_menu).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.scale_btn:
                showScalePop();
                break;
            case R.id.from_bottom_btn:
                showBottomPop();
                break;
            case R.id.from_top_btn:
                startActivity(new Intent(Main2Activity.this,FromTopActivity.class));
                break;
            case R.id.auto_located_btn:
                jumpToActivity(AutoLocatedActivity.class);
                break;
            case R.id.popup_menu:
                jumpToActivity(PopupMenuActivity.class);
                break;

        }

    }

    private void jumpToActivity(Class c){
        Intent intent = new Intent(this,c);
        startActivity(intent);
    }

    private void showBottomPop() {
        SlideFromBottomPopup frombottomPopup = new SlideFromBottomPopup(Main2Activity.this,listener);
        frombottomPopup.showPopupWindow();
    }

    ScalePopup scalePopup;

    private void showScalePop() {

        scalePopup = new ScalePopup(Main2Activity.this,listener);
        scalePopup.showPopupWindow();

        scalePopup.setOnDismissListener(new BasePopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                Toast.makeText(Main2Activity.this, "dismiss", Toast.LENGTH_SHORT).show();
            }
        });




    }
}
